Skip to content

Use Cow for AppError message#16

Merged
RAprogramm merged 2 commits intomainfrom
codex/change-message-type-to-cow
Sep 11, 2025
Merged

Use Cow for AppError message#16
RAprogramm merged 2 commits intomainfrom
codex/change-message-type-to-cow

Conversation

@RAprogramm
Copy link
Owner

Summary

  • store AppError message as Cow<'static, str> and accept borrowed or owned strings
  • convert AppError into ErrorResponse without extra allocations
  • adjust reqwest conversion test for the new message type

Testing

  • cargo clippy --all-targets -- -D warnings
  • cargo build --all-targets
  • cargo test --all
  • cargo doc --no-deps

https://chatgpt.com/codex/tasks/task_e_68c275eacc48832bbf2e2fbffb2de46d

@RAprogramm RAprogramm merged commit b78fd42 into main Sep 11, 2025
1 of 2 checks passed
@RAprogramm RAprogramm deleted the codex/change-message-type-to-cow branch September 11, 2025 07:16
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex Review: Here are some suggestions.

Reply with @codex fix comments to fix any unresolved comments.

About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".

Comment on lines 102 to 106
///
/// Prefer named helpers (e.g. [`AppError::not_found`]) where it clarifies
/// intent.
pub fn with(kind: AppErrorKind, msg: impl Into<String>) -> Self {
pub fn with(kind: AppErrorKind, msg: impl Into<Cow<'static, str>>) -> Self {
Self {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Restrict AppError constructors to 'static string slices

Changing the message parameter to impl Into<Cow<'static, str>> means only 'static borrows are accepted. Callers that previously passed short‑lived &str values (e.g. AppError::bad_request(err.as_str())) now hit a compile error because such slices no longer implement Into<Cow<'static, str>>. This contradicts the stated goal of accepting borrowed or owned strings and introduces a breaking API change unless every non‑static borrow is converted to String first. Consider accepting impl Into<Cow<'_, str>> and promoting non‑'static values to owned strings internally, or keep the original impl Into<String> and wrap with Cow::Owned so existing call sites continue to compile.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant